<?php
namespace App\Services;

use Spatie\Image\Image;
use Spatie\Image\Manipulations;

class UploadService{

   public function image($file,$width=800,$height=800,$fit=Manipulations::FIT_CONTAIN){
        // attachments/xxxx.png
        $filePath = $file->store('attachments');
        // storage/app/attachments/xxxx.png
        $realPath = storage_path('app/'.$filePath);
        Image::load($realPath)->fit($fit,$width,$height)->save();
        //http://bbs.test/attachments/xxxx.png
        return url($filePath);
   }
}
